home *** CD-ROM | disk | FTP | other *** search
- /**\
- |**| =====================================================================
- |**|
- |**| put your code here.c
- |**|
- |**| This file contains the calls that an application needs to make
- |**| the QuickDraw GX shell work correctly.
- |**|
- |**| QuickDraw GX Libraries Used:
- |**| "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c",
- |**| "ShapeLibrary.c", and "TransformLibrary.c".
- |**|
- |**| ©1992-1996 Apple Computer, Inc.
- |**| All rights reserved.
- |**|
- |**| =====================================================================
- \**/
-
-
- #include "QDGX shell.h"
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| PROTOTYPES
- |**| ---------------------------------------------------------------------
- \**/
-
- // funtions required by shell
-
- void DoSetup (void);
- void DoDraw (WindowPtr wind, Boolean updating);
- OSErr DoCreateNew (void);
- void DoDispose (WindowPtr wind);
- void DoIdle (WindowPtr wind);
- void DoTeardown (void);
- void DoClick (WindowPtr wind, Point p);
-
- // private functions
-
- OSErr DoWindowInit (WindowPtr wind);
- void CreateSampleImage (WindowPtr wind);
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| ENUMS
- |**| ---------------------------------------------------------------------
- \**/
- enum { rWindResource = 128 };
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| GLOBALS
- |**| ---------------------------------------------------------------------
- \**/
-
- // Set "gGiveMeValidation" to TRUE if you want receive run-time validation.
-
- Boolean gGiveMeValidation = true;
-
-
- // gGraphicsHeapSize sets the size of the graphics heap created by calling the
- // GXNewGraphicsClient routine in main () within QuickDraw GX shell.c. You can determine
- // the amount of graphics heap required by using GraphicsBug. I'm giving it 600K,
- // since we need abunch if we have several windows open.
-
- long gGraphicsHeapSize = 600;
-
- // gOurPrintingOverrideUPP is a universal proc pointer for our printing event
- // override. This is so that our override can be native PowerPC code if necessary.
-
- GXPrintingEventUPP gOurPrintingOverrideUPP;
-
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoSetup()
- |**| Here's where we initialize any global variables our application needs.
- |**| We have only one at this time -- the universal proc pointer for
- |**| our printing override.
- |**| ---------------------------------------------------------------------
- \**/
- void DoSetup (void)
- { // Initialize our printing event override UPP
- gOurPrintingOverrideUPP = NewGXPrintingEventProc(MyPrintingEventOverride);
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoDraw()
- |**| Draw the contents of the window. The first parameter is the window
- |**| to draw, and the second parameter is true if we're updating an existing
- |**| image. If that's the case, we don't want to change anything, but
- |**| just draw what's already there.
- |**| ---------------------------------------------------------------------
- \**/
- void DoDraw (WindowPtr wind, Boolean updating)
- {
- #pragma unused (updating)
- GXDrawShape (GetDocShape(wind));
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoCreateNew()
- |**| This routine is called when a window needs to be created.
- |**| ---------------------------------------------------------------------
- \**/
- OSErr DoCreateNew (void)
- {
- OSErr err = noErr;
- WindowPtr wind;
-
- // Get and create our window from the resource fork
-
- wind = GetNewWindow(rWindResource, nil, (WindowPtr)-1L);
-
- // Attach a default gxViewPort to it, create and iInitialize our
- // private data for it, and add a sample image to its page shape.
-
- if ( wind == NULL )
- return (MemError());
-
- GXIgnoreGraphicsNotice(transform_already_set);
- SetDefaultViewPort(GXNewWindowViewPort(wind));
- GXPopGraphicsNotice();
-
- err = DoWindowInit(wind);
- if ( err != noErr )
- return err;
-
- CreateSampleImage(wind);
- return err;
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoDispose()
- |**| This routine is called when a window needs to be disposed of.
- |**| ---------------------------------------------------------------------
- \**/
- void DoDispose (WindowPtr wind)
- {
- TH_Doc doc;
-
- // You should always dispose of your GX graphics objects before tossing your window.
- // Why? It's generally good form and this approach guarantees that everything is
- // disposed. If you had not disposed of everything, the call to DisposeWindow should
- // dispose of the objects. If you are running the debugging version of QuickDraw GX
- // with notices set, you will receive a notice that you had not disposed of everything.
- // You can turn notices on in this file by not #defineing debugging.
-
- if ( wind != NULL )
- {
- doc = (TH_Doc)GetWRefCon(wind); // Remember, this is where we stored our private data.
- GXDisposeShape(GetDocShape(wind)); // Dispose of this doc's shape.
- GXDisposeJob(GetDocJob(wind)); // Dispose of this doc's print job.
- DisposHandle((Handle) doc); // Dispose of our private data.
- DisposeWindow(wind); // Dispose of the window.
- }
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoIdle()
- |**| This routine is called to do things while idling through the event loop.
- |**| ---------------------------------------------------------------------
- \**/
- void DoIdle (WindowPtr wind)
- {
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoTeardown()
- |**| This routine is called just before we quit to remove anything
- |**| persistent that might have been setup by DoSetup().
- |**| ---------------------------------------------------------------------
- \**/
- void DoTeardown (void)
- {
- DisposeRoutineDescriptor(gOurPrintingOverrideUPP);
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoClick()
- |**| ---------------------------------------------------------------------
- \**/
- void DoClick(WindowPtr window, Point p)
- {
- }
-
-
-
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoWindowInit()
- |**| In this function we create and initialize the the private document
- |**| structure for a new window. This structure contains the print job and
- |**| the shape which is drawn in the window. We store this data in a handle
- |**| and hang it off the window's refCon field for easy retrieval. By doing
- |**| this, rather than using globals, we can create many windows containing
- |**| unique print jobs and shapes.
- |**| ---------------------------------------------------------------------
- \**/
- OSErr DoWindowInit (WindowPtr wind)
- {
- OSErr err = noErr;
- gxJob docJob;
- gxShape docPage;
- TH_Doc windDoc;
-
-
- // Create the page shape. We set the unique items attribute to make sure that each item
- // added to the picture has a unique reference. If this attribute was not set, we would
- // not see all copies of anything we add to the shape multiple times -- we'd just see
- // the last version added.
-
- docPage = GXNewShape(gxPictureType);
- GXSetShapeAttributes(docPage, (GXGetShapeAttributes(docPage) | gxUniqueItemsShape));
-
-
- // Create a print job for this document. This will be the same as the system default until
- // the user goes through the dialogs for Page Setup or Print…
-
- err = GXNewJob(&docJob);
-
-
- // If there are no errors, create a handle the size of our document structure and store
- // the print job and page shape in it. Store the handle in the window's refCon field so
- // that we can get at it. (Note that the utility routines "GetDocJob" and "GetDocShape"
- // can be used to do this easily.
-
- if ( err == noErr )
- {
- windDoc = (TH_Doc) NewHandleClear(sizeof(T_Doc));
-
- if ( windDoc == NULL )
- err = MemError();
- else
- {
- (*windDoc)->docJob = docJob;
- (*windDoc)->docPage = docPage;
- SetWRefCon(wind, (long) windDoc);
- }
-
- // Now install our application override for PrintingEvent so that we can
- // support the new movable-modal printing dialog boxes.
-
- GXInstallApplicationOverride(docJob, gxPrintingEventMsg, gOurPrintingOverrideUPP);
-
- }
-
- return err;
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| CreateSampleImage()
- |**| This function creates primitive shapes and adds them to the window's page shape.
- |**| ---------------------------------------------------------------------
- \**/
- void CreateSampleImage (WindowPtr wind)
- {
- gxShape thePage;
- gxShape theLine;
- gxLine lineData = {{ff(25), ff(25)}, {ff(125), ff(125)}};
- gxShape theRect;
- gxRectangle rectData = {ff(25), ff(25), ff(75), ff(75)};
- gxShape theCurve;
- gxCurve curveData = {{ff(25), ff(25)}, {ff(275), ff(75)}, {ff(125), ff(125)}};
- gxShape thePath;
- long tripleEightData[] = { 1 /* # of contours */,
- 6 /* # of points */,
- 0xff000000,
- 0, 0, // the points
- ff(75), 0,
- ff(5), ff(50),
- ff(75), ff(100),
- 0, ff(100),
- ff(75), ff(50)};
- gxShape theText;
- gxRectangle theTextBounds;
- gxColor textColor;
- Fixed x,y;
- short loop;
- gxShape thePolygon;
- long starData[] = { 1, // number of contours
- 5 , // number of points
- ff(60), 0, ff(90), ff(90), ff(0), ff(30),
- ff(120), ff(30), ff(0), ff(90)}; // the points
-
-
- // Retrieve the page shape so we can add to it.
-
- thePage = GetDocShape(wind);
-
-
- // Create a line
-
- theLine = GXNewLine (&lineData);
-
- AddToShape(thePage, theLine);
- GXDisposeShape(theLine);
-
-
- // Create a rectangle which is: red & is draw with it's frame.
-
- theRect = GXNewRectangle(&rectData);
- SetShapeCommonColor (theRect, red);
- GXSetShapeFill (theRect, gxClosedFrameFill);
- GXMoveShapeTo (theRect, ff(150), ff(25));
-
- AddToShape(thePage, theRect);
- GXDisposeShape(theRect);
-
-
- // Create a curve which has: a 3.25 pen thickness
-
- theCurve = GXNewCurve(&curveData);
-
- // The fl marco converts floating gxPoint #'s to Fixed gxPoint.
- GXSetShapePen(theCurve, fl(3.25));
- GXMoveShapeTo (theCurve, ff(210), ff(25));
-
- AddToShape(thePage, theCurve);
- GXDisposeShape(theCurve);
-
-
- // Create apath which has: a 2 pen thickness, its color is green, and its drawn with its frame
-
- thePath = GXNewPaths((gxPaths *) tripleEightData);
- GXSetShapeFill (thePath, gxClosedFrameFill);
- GXSetShapePen(thePath, ff(2));
- SetShapeCommonColor (thePath, green);
-
- GXMoveShapeTo (thePath, ff(390), ff(25));
-
- AddToShape(thePage, thePath);
- GXDisposeShape(thePath);
-
-
- // Create a character S which is: colored in hsv space and it is rotated 15 degrees - six times
- // via the left bottom corner. Create the text, set the font size, and set the font name
-
- theText = GXNewText(1,(unsigned char*)"S", nil);
- SetShapeCommonFont(theText, timesFont);
- GXSetShapeTextSize(theText, ff(200));
- GXMoveShapeTo (theText, ff(25), ff(275));
- GXSetShapeAttributes (theText, (GXGetShapeAttributes(theText) | gxMapTransformShape));
-
-
- // Create an hsv color space and set up the initial colors
-
- textColor.space = gxHSVSpace;
- textColor.profile = nil;
- textColor.element.hsv.hue = 0x7400;
- textColor.element.hsv.saturation = 0xFFFF;
- textColor.element.hsv.value = 0xFFFF;
-
-
- // Get the bounds of "theText" and determine the bottom left corner
-
- GXGetShapeBounds(theText, 0L, &theTextBounds);
- x = theTextBounds.left;
- y = theTextBounds.bottom;
-
-
- // Rotate "theText" 15 degrees - 6 times. Add each letter to the picture.
-
- for (loop = 0; loop < 6; loop++) {
- GXSetShapeColor(theText, &textColor);
- GXRotateShape(theText, ff(15), x, y);
-
- AddToShape(thePage, theText);
-
- textColor.element.hsv.hue += 0x0940;
- }
-
- GXDisposeShape(theText);
-
-
- // Create a polygon which has the following features: yellow, drawn with a pen = 3, and
- // skew it in the vertical direction by 0.5
-
- thePolygon = GXNewPolygons((gxPolygons *) starData);
- GXSetShapeFill(thePolygon, gxEvenOddFill);
- GXSetShapePen (thePolygon, ff(3));
- SetShapeCommonColor (thePolygon, yellow);
- GXMoveShapeTo (thePolygon, ff(240), ff(110));
- GXSkewShape(thePolygon, 0, fl(0.5), 0, 0);
-
- AddToShape(thePage, thePolygon);
- GXDisposeShape(thePolygon);
-
-
- // Invalidate the window's portRect so that everything gets updated.
-
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-